#pragma once
#include <QObject>
#include <QUdpSocket>
#include <QMutex>
#include "MessageHelper.h"

class UDPSocketWorker : public QObject
{
    Q_OBJECT
public:
    static const int MAX_QUEUE_SIZE = 500;

    explicit UDPSocketWorker(QObject *parent = nullptr);
    ~UDPSocketWorker();

public slots:
    void process();
    void sendMessage(const MSG &message);
    void sendPing();

signals:
    void messageReceived(const MSG &message);
    void errorEmit(const QString &errorString);
    void connected();

private slots:
    void onReadyRead();
    void onError(QAbstractSocket::SocketError error);

private:
    QUdpSocket *socket;
    QMutex mutex;
};
